SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[usp_AddEmailSender]
	
	(
	 @param_Admin_LoginID VARCHAR(50),
      @param_sender VARCHAR(50),
      @param_smtpaddress VARCHAR(50),
      @param_username VARCHAR(50),
      @param_password VARCHAR(50),
      @param_emailaddress VARCHAR(50),
      @param_is_default Bit,
      @param_add_time SmallDateTime,
      @param_user_add VARCHAR(50)
      
	)
	
AS
	/* SET NOCOUNT ON */
	 DECLARE @Count INT
                 SET @Count = (
                        SELECT   COUNT(*)
                        FROM     dbo.JOL_EmailManagement_Sender
                        WHERE    Admin_LoginID = @param_Admin_LoginID and emailaddress=@param_emailaddress
                        )
                IF @Count = 0 
                    INSERT  INTO dbo.JOL_EmailManagement_Sender
                            (
                             Admin_LoginID,
                             sender,
                             smtpaddress,
                             username,
                             password,
                             emailaddress,
                             is_default,
                             add_time,
                             user_add
                             
                             
                            )
                    VALUES  (
							@param_Admin_LoginID,
							@param_sender,
							@param_smtpaddress,
							@param_username,
							@param_password,
							@param_emailaddress,
							@param_is_default,
							@param_add_time,
							@param_user_add
							
                              
                            )
                             IF @param_is_default='TRUE'
						update dbo.JOL_EmailManagement_Sender 
						set is_default='false' where Admin_LoginID=@param_Admin_LoginID and  is_default='TRUE' and emailaddress<>@param_emailaddress
                ELSE
                        SELECT  '已存在该发件箱，不能再添加，请转到修改页面'
GO
